package day21.pack1;

public class Sell extends Thread {
    private String type; // 线上/线下
    private Repository repository; // 仓库

    public Sell(Repository repository, String type) {
        this.repository = repository;
        this.type = type;
    }

    public void run() {
        while (repository.getCount() > 0) {
            synchronized (repository) {
                if(repository.getCount() > 0) {
                    int count = repository.getCount();
                    System.out.println("[" + type + "]成功购买了第：【" + (10001 - count) + "】台游戏机!");
                    repository.setCount(count - 1);
                }
            }
        }
    }
}
